package com.itheima.springbootwebtlias.service.impl;

import com.itheima.springbootwebtlias.mapper.EmpMapper;
import com.itheima.springbootwebtlias.mapper.StudentMapper;
import com.itheima.springbootwebtlias.service.ReportService;
import com.itheima.springbootwebtlias.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper  studentMapper;

    //统计职位数据(柱状图)
    @Override
    public Map jobCount() {
        //1.调用持久层EmpMapper查询统计职位数据
        List<Map> jobList = empMapper.jobCount();

        //2.处理查询结果
        Map map = new HashMap<>();
        map.put("jobList", jobList.stream().map(item -> item.get("name")).collect(Collectors.toList()));
        map.put("dataList", jobList.stream().map(item -> item.get("value")).collect(Collectors.toList()));
        //3.返回响应结果
        return map;
    }

    //统计性别数据饼图
    @Override
    public List<Map> genderCount() {
        //1.调用持久层EmpMapper查询统计性别数据
        return empMapper.genderCount();

    }

    //5.4 班级人数统计(柱状图)
    @Override
    public Map studentsCount() {
        //1.调用持久层EmpMapper查询班级人数统计
        List<Map> studentsCount = studentMapper.studentsCount();

        //2.处理查询结果
        Map map = new HashMap<>();
        map.put("clazzList", studentsCount.stream().map(item -> item.get("name")).collect(Collectors.toList()));
        map.put("dataList", studentsCount.stream().map(item -> item.get("value")).collect(Collectors.toList()));
        //3.返回响应结果
        return map;

    }
    //5.3 学员学历统计(饼图)
    @Override
    public List<Map> studentDegreeCount() {
        //1.调用业务层功能方法，查询学员学历统计
        return studentMapper.studenDegreeCount();
    }
}
